package cn.imvc.app.controllers.system;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.entities.Position;
import cn.imvc.app.models.PositionDepartmentModel;
import cn.imvc.app.models.PositionModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;

public class PositionControllerImpl implements PositionController {
	
	public Page<Position> page;
	public ViewRequest viewRequest;
	public Position position;
	public String positions;
	public int id;
	public int[] ids;
	@Autowired
	private PositionModel positionModel;
	@Autowired
	private PositionDepartmentModel positionDepartmentModel;

	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}


	public void setPosition(Position position) {
		this.position = position;
	}


	public void setId(int id) {
		this.id = id;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}

	public String search() {
		return "position/search";
	}

	public String index() {
		page=positionModel.find(viewRequest);
		return "position/index";
	}

	public String show() {
		position=positionModel.get(id);
		return "position/show";
	}
	public String detail(){
		position=positionModel.get(id);
		return "position/detail";
	}

	public String editNew() {
		return "position/editNew";
	}

	public String create() {
		positionModel.save(position);
		return Render.json(new DialogBean("200", "创建成功","position", "closeCurrent"));
	}

	public String edit() {
		position=positionModel.get(id);
		return "position/edit";
	}

	public String update() {
		positionModel.update(id, position);
		return Render.json(new DialogBean("200", "修改成功","position", "closeCurrent"));
	}

	public String destroy() {
		positionModel.delete(id);
		return Render.json(new DialogBean("200", "删除成功","position"));
	}

	public String destroyBatch() {
		positionModel.deleteBatch(ids);
		return Render.json(new DialogBean("200", "删除成功","position"));
	}

	public String treeLookup(){
		positions=positionModel.treeLookup(id);
		return "position/treeLookup";
	}
	public String lookupSuggest(){
		return Render.json(positionModel.lookupSuggest(id));
	}
	
}
